using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class MenuController : MonoBehaviour
{
    [Header("Scene Settings")]
    [SerializeField] private string gameSceneName = "SampleScene";

    [Header("Sound Settings")]
    [SerializeField] private AudioSource buttonAudioSource;
    [SerializeField] private float delayBeforeSceneLoad = 0.3f;

    private bool isTransitioning = false;

    private void Start()
    {
        Time.timeScale = 1f;

        Cursor.lockState = CursorLockMode.None;
        Cursor.visible = true;
    }

    public void PlayGame()
    {
        if (!isTransitioning)
        {
            StartCoroutine(PlayGameWithDelay());
        }
    }

    private IEnumerator PlayGameWithDelay()
    {
        isTransitioning = true;

        yield return new WaitForSecondsRealtime(delayBeforeSceneLoad);

        SceneManager.LoadScene(gameSceneName);
    }

    public void QuitGame()
    {
        if (!isTransitioning)
        {
            StartCoroutine(QuitGameWithDelay());
        }
    }

    private IEnumerator QuitGameWithDelay()
    {
        isTransitioning = true;

        yield return new WaitForSecondsRealtime(delayBeforeSceneLoad);

   
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
    }
}